#include <cassert>
#include <curses.h>
#include <cdk/cdk.h>
#include "editbox.h"
#include "_editbox.h"
#include "window.h"
#include "_mediator.h"

Factory<EditBox> EditBox::create;

EditBox::EditBox(shared_ptr<Window> w) : p(new P) {
  p->handle_ = newCDKEntry(Mediator::get_cdk_screen(w),
    0,
    0,
    0,
    0,
    0,
    0,
    vMIXED,
    0,
    0,
    0,
    true,
    true);
  assert(p->handle_ != NULL);
}

EditBox::~EditBox() {
  destroyCDKEntry(p->handle_);
}

EditBox& EditBox::activate() {
  activateCDKEntry(p->handle_, NULL);
  return *this;
}

EditBox& EditBox::hide() {
  eraseCDKEntry(p->handle_);
  return *this;
}

EditBox& EditBox::show() {
  drawCDKEntry(p->handle_, has_box());
  return *this;
}

EditBox& EditBox::move(const int& x, const int& y) {
  moveCDKEntry(p->handle_, x, y, false, true);
  return *this;
}

bool EditBox::has_box() {
  return getCDKEntryBox(p->handle_) == true;
}

